package com.gy.edu.home;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.gy.edu.R;
import com.gy.edu.base.BaseActivity;
import com.gy.edu.home.adapter.ClassAnsAdapter;
import com.gy.edu.home.adapter.ClassCatalogAdapter;
import com.gy.edu.home.adapter.ClassCommentAdapter;
import com.gy.edu.home.bean.HomeBean;
import com.gy.edu.util.AnimUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.Calendar;

/**
 * Created by 高岳 on 2016/12/22.
 * Describe:课程详情
 */
public class ClassDetailActivity extends BaseActivity {

    private TextView tvTitle, tvName, tvCatalog, tvDes, tvComment, tvAns;
    private LinearLayout llCatalog, llDes, llComment, llAns;
    private ListView listViewCatalog, listViewComment, listViewAns;
    private ClassCatalogAdapter catalogAdapter;//目录
    private ClassCommentAdapter commentAdapter;//评论adapter
    private ClassAnsAdapter ansAdapter;//知识问答
    private HomeBean bean;
    private ImageView img;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_class_detail);
        setTitleMsg("苏州职教智慧云课堂");
        img = (ImageView) findViewById(R.id.class_detail_img);
        _imgRight.setImageResource(R.mipmap.to_download);
        _imgRightTwo.setImageResource(R.mipmap.attention_unselected);
        tvTitle = (TextView) findViewById(R.id.class_detail_title);
        tvName = (TextView) findViewById(R.id.class_detail_name);
        tvCatalog = (TextView) findViewById(R.id.class_detail_tv_catalog);
        tvDes = (TextView) findViewById(R.id.class_detail_tv_des);
        tvComment = (TextView) findViewById(R.id.class_detail_tv_comment);
        tvAns = (TextView) findViewById(R.id.class_detail_tv_ans);
        llCatalog = (LinearLayout) findViewById(R.id.class_detail_ll_catalog);
        llDes = (LinearLayout) findViewById(R.id.class_detail_ll_des);
        llComment = (LinearLayout) findViewById(R.id.class_detail_ll_comment);
        llAns = (LinearLayout) findViewById(R.id.class_detail_ll_ans);
        listViewCatalog = (ListView) findViewById(R.id.class_detail_list_catalog);
        listViewComment = (ListView) findViewById(R.id.class_detail_list_comment);
        listViewAns = (ListView) findViewById(R.id.class_detail_list_ans);
    }

    @Override
    protected void initData() {
        bean = (HomeBean) getIntent().getSerializableExtra("bean");
        catalogAdapter = new ClassCatalogAdapter(this);
        commentAdapter = new ClassCommentAdapter(this);
        ansAdapter = new ClassAnsAdapter(this);
    }

    @Override
    protected void setListener() {
        super.setListener();
        tvCatalog.setOnClickListener(this);
        tvDes.setOnClickListener(this);
        tvComment.setOnClickListener(this);
        tvAns.setOnClickListener(this);
        llCatalog.setOnClickListener(this);
        llDes.setOnClickListener(this);
        llComment.setOnClickListener(this);
        llAns.setOnClickListener(this);

        listViewCatalog.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //                if(position != 0 && position != 10){
                Intent intent;
                //                    if(position % 2 == 1){
                //                        intent = new Intent(ClassDetailActivity.this, FileDetailActivity.class);
                //                    } else {
                intent = new Intent(ClassDetailActivity.this, VideoDetailActivity.class);
                //                    }
                Calendar cal = Calendar.getInstance();
                int mi = cal.get(Calendar.SECOND);
                position = mi % 3;
                intent.putExtra("position",position);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(ClassDetailActivity.this);
                //                }
            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        if (bean != null) {
            tvTitle.setText(bean.title + "");
            tvName.setText(bean.name + "");
            String uri = "drawable://" + bean.img;
            ImageLoader.getInstance().displayImage(uri, img);
        }
        listViewCatalog.setAdapter(catalogAdapter);
        listViewComment.setAdapter(commentAdapter);
        listViewAns.setAdapter(ansAdapter);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.class_detail_tv_catalog:
                tvCatalog.setBackgroundResource(R.mipmap.tap_left);
                tvDes.setBackgroundResource(R.mipmap.tap_not_center);
                tvComment.setBackgroundResource(R.mipmap.tap_not_center);
                tvAns.setBackgroundResource(R.mipmap.tap_not_right);
                tvCatalog.setTextColor(getResources().getColor(R.color.white));
                tvDes.setTextColor(getResources().getColor(R.color.title_bg));
                tvComment.setTextColor(getResources().getColor(R.color.title_bg));
                tvAns.setTextColor(getResources().getColor(R.color.title_bg));
                llCatalog.setVisibility(View.VISIBLE);
                llDes.setVisibility(View.GONE);
                llComment.setVisibility(View.GONE);
                llAns.setVisibility(View.GONE);
                break;
            case R.id.class_detail_tv_des:
                tvCatalog.setBackgroundResource(R.mipmap.tap_not_left);
                tvDes.setBackgroundResource(R.mipmap.tap_center);
                tvComment.setBackgroundResource(R.mipmap.tap_not_center);
                tvAns.setBackgroundResource(R.mipmap.tap_not_right);
                tvCatalog.setTextColor(getResources().getColor(R.color.title_bg));
                tvDes.setTextColor(getResources().getColor(R.color.white));
                tvComment.setTextColor(getResources().getColor(R.color.title_bg));
                tvAns.setTextColor(getResources().getColor(R.color.title_bg));
                llCatalog.setVisibility(View.GONE);
                llDes.setVisibility(View.VISIBLE);
                llComment.setVisibility(View.GONE);
                llAns.setVisibility(View.GONE);
                break;
            case R.id.class_detail_tv_comment:
                tvCatalog.setBackgroundResource(R.mipmap.tap_not_left);
                tvDes.setBackgroundResource(R.mipmap.tap_not_center);
                tvComment.setBackgroundResource(R.mipmap.tap_center);
                tvAns.setBackgroundResource(R.mipmap.tap_not_right);
                tvCatalog.setTextColor(getResources().getColor(R.color.title_bg));
                tvDes.setTextColor(getResources().getColor(R.color.title_bg));
                tvComment.setTextColor(getResources().getColor(R.color.white));
                tvAns.setTextColor(getResources().getColor(R.color.title_bg));
                llCatalog.setVisibility(View.GONE);
                llDes.setVisibility(View.GONE);
                llComment.setVisibility(View.VISIBLE);
                llAns.setVisibility(View.GONE);
                break;
            case R.id.class_detail_tv_ans:
                tvCatalog.setBackgroundResource(R.mipmap.tap_not_left);
                tvDes.setBackgroundResource(R.mipmap.tap_not_center);
                tvComment.setBackgroundResource(R.mipmap.tap_not_center);
                tvAns.setBackgroundResource(R.mipmap.tap_right);
                tvCatalog.setTextColor(getResources().getColor(R.color.title_bg));
                tvDes.setTextColor(getResources().getColor(R.color.title_bg));
                tvComment.setTextColor(getResources().getColor(R.color.title_bg));
                tvAns.setTextColor(getResources().getColor(R.color.white));
                llCatalog.setVisibility(View.GONE);
                llDes.setVisibility(View.GONE);
                llComment.setVisibility(View.GONE);
                llAns.setVisibility(View.VISIBLE);
                break;
        }
    }
}
